package com.sooth.micro.camunda.converter.bean;

import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.sooth.micro.camunda.converter.bean.event.intermediate.IntermediateCatchEventDefinition;
import com.sooth.micro.camunda.converter.bean.event.start.EndEventDefinition;
import com.sooth.micro.camunda.converter.bean.event.start.StartEventDefinition;
import com.sooth.micro.camunda.converter.bean.extension.ButtonPerm;
import com.sooth.micro.camunda.converter.bean.extension.FormPerm;
import com.sooth.micro.camunda.converter.bean.gateway.ExclusiveGatewayDefinition;
import com.sooth.micro.camunda.converter.bean.gateway.InclusiveGatewayDefinition;
import com.sooth.micro.camunda.converter.bean.gateway.ParallelGatewayDefinition;
import com.sooth.micro.camunda.converter.bean.listener.ExecutionListener;
import com.sooth.micro.camunda.converter.bean.subprocess.CallActivityDefinition;
import com.sooth.micro.camunda.converter.bean.subprocess.SubProcessDefinition;
import com.sooth.micro.camunda.converter.bean.task.*;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

@Data
@NoArgsConstructor
@JsonTypeInfo(
        use = JsonTypeInfo.Id.NAME,
        include = JsonTypeInfo.As.EXISTING_PROPERTY,
        property = "nodeType",
        visible = true)
@JsonSubTypes({
        // event
        @JsonSubTypes.Type(value = StartEventDefinition.class, name = "startEvent"),
        @JsonSubTypes.Type(value = EndEventDefinition.class, name = "endEvent"),

        // task
        @JsonSubTypes.Type(value = UserTaskDefinition.class, name = "userTask"),
        @JsonSubTypes.Type(value = ServiceTaskDefinition.class, name = "serviceTask"),
        @JsonSubTypes.Type(value = ScriptTaskDefinition.class, name = "scriptTask"),
        @JsonSubTypes.Type(value = ReceiveTaskDefinition.class, name = "receiveTask"),
        @JsonSubTypes.Type(value = ManualTaskDefinition.class, name = "manualTask"),
        @JsonSubTypes.Type(value = BusinessRuleTaskDefinition.class, name = "businessRuleTask"),

        // sub process
        @JsonSubTypes.Type(value = CallActivityDefinition.class, name = "callActivity"),
        @JsonSubTypes.Type(value = SubProcessDefinition.class, name = "subProcess"),

        // gateway
        @JsonSubTypes.Type(value = ParallelGatewayDefinition.class, name = "parallelGateway"),
        @JsonSubTypes.Type(value = ExclusiveGatewayDefinition.class, name = "exclusiveGateway"),
        @JsonSubTypes.Type(value = InclusiveGatewayDefinition.class, name = "inclusiveGateway"),

        // catch event
        @JsonSubTypes.Type(
                value = IntermediateCatchEventDefinition.class,
                name = "intermediateCatchEvent")
})
public abstract class BaseDefinition implements Serializable {
    private String id;

    private Long pageId;

    /**
     * 节点名称
     */
    private String nodeName;

    /**
     * 节点类型
     */
    private String nodeType;

    /**
     * 入度节点
     */
    private List<String> incoming;

    /**
     * 后继节点
     */
    private BaseDefinition nextNode;

    /**
     * 页面权限
     */
    private List<FormPerm> formPermList;

    /**
     * 按钮权限
     */
    private List<ButtonPerm> buttonPermList;

    /**
     * 执行监听器
     */
    private List<ExecutionListener> listeners = new ArrayList();

    public abstract String getNodeType();
}
